Figure 11.9
Program LeastSq fitting a line to a set of points.
You can then take the partial derivatives of this equation with respect to a, b, and c.
dE/da = S 2 * (a * xi2 + b * xi + c - yi) * xi2 = 2 * (a * S xi4 + b * S xi3 + c * S xi2 - S yi * xi2) dE/db = S 2 * (a * xi2 + b * xi + c - yi) * xi = 2 * (a * S xi3 + b * S xi2 + c * S xi - S yi * xi) dE/dc = S 2 * (a * xi2 + b * xi + c - yi)
= 2 * (a * S xi2 + b * S xi + c * S 1 - S yi)
Once again, the values xi and yi values are just numbers, so you can compute the values of the summations. For convenience, let:
A = S xi4 B = S xi3 C = S xi2 D = S yi * xi2 E = S xi F = S yi * xi G = S yi
Substituting these values into the partial derivatives, setting them equal to zero, and rearranging a bit gives you the three equations:
a * A + b * B + c * C = D
a * B + b * C + c * E = F
a * C + b * E + c * N + G
You can now solve these three equations for the three unknowns a, b, and c to get:
a = [(C * D - B * F) * (E2 - C * N) - (E * F - C * G) * (C2 - B * E)] /
[(A * C - B2) * (E2 - C * N) + (C2 - B * E)2]